#! /usr/bin/env python
# -*- coding: utf-8 -*-

from playwright.sync_api import Page
from ui_automation_test.common.base_page import BasePage
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.planConfig.warrantyLiabilityPlanConfig.dutyPerson.loc_duty_person_search import LocSearchDutyPerson
from ui_automation_test.common.logger import logger
from ui_automation_test.locators.dualPrevention.riskCheckTaskManagement.planConfig.warrantyLiabilityPlanConfig.loc_warranty_liability_plan_config import LocWarrantyLiabilityPlanConfig


class DutyPerson(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('双重预防机制')
        self.switch_menu('隐患排查任务管理')
        self.switch_menu('计划配置')
        self.switch_menu('包保责任计划配置')
    

    def search_duty_person(self, company, object_name, dept):
        """
        包保责任人查询
        :param company: 所属企业
        :param object_name: 风险分析对象名称
        :param department: 责任部门
        """
        logger.info('点击包保责任人管理按钮')
        self.click(LocWarrantyLiabilityPlanConfig.loc_warranty_liability_person_button)
        logger.info('开始包保责任人查询')
        if company:
            logger.info(f'选择所属企业: {company}')
            self.select(LocSearchDutyPerson.loc_company_select, company)
        if object_name:
            logger.info(f'选择所属风险分析对象: {object_name}')
            self.select(LocSearchDutyPerson.loc_object_select, object_name)
        if dept:
            logger.info(f'选择责任部门: {dept}')
            self.select(LocSearchDutyPerson.loc_department_select, dept)
        logger.info('点击查询按钮')
        self.click(LocSearchDutyPerson.loc_search_button)
